#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->dockWidget_Fog_pref->setVisible(false);
    ui->dockWidget_Ground_pref->setVisible(false);
    ui->dockWidget_Sky_pref->setVisible(false);
    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(onTimer()));
    timer->start(10);
    ui->skyTexFileName->setText(ui->glWidget->getSkyTex());
    ui->groundTexFileName->setText(ui->glWidget->getHMapTex());
    ui->groundRawFileName->setText(ui->glWidget->getHMapRaw());
    if(ui->glWidget->showSky)
        ui->checkBoxSkyVisible->setCheckState(Qt::Checked);
    if(ui->glWidget->showMap)
        ui->checkBoxGroundVisible->setCheckState(Qt::Checked);
    if(ui->glWidget->showFog)
        ui->checkBoxFogVisible->setCheckState(Qt::Checked);
    ui->fogDens->setValue(ui->glWidget->density*1000);
    ui->densLbl->setText((QString)"Density (" + QString::number(ui->glWidget->density) + ")");
}
MainWindow::~MainWindow()
{
    delete ui;
    delete timer;
}
void MainWindow::on_actionFog_toggled(bool vz)
{
    ui->dockWidget_Fog_pref->setVisible(vz);
}
void MainWindow::on_actionSky_toggled(bool vz)
{
    ui->dockWidget_Sky_pref->setVisible(vz);
}
void MainWindow::on_actionGround_toggled(bool vz)
{
    ui->dockWidget_Ground_pref->setVisible(vz);

}
void MainWindow::onTimer()
{
    ui->glWidget->onTimer();
    ui->dbgEdit->setHtml(ui->glWidget->getDbg());
    this->repaint();

}
void MainWindow::on_actionSave_Default_triggered()
{
    ui->glWidget->saveSettings();
}
void MainWindow::on_brSkyTex_clicked()
{
    ui->glWidget->setSkyTex();
    ui->glWidget->drawSky(false);
    ui->skyTexFileName->setText(ui->glWidget->getSkyTex());
}
void MainWindow::on_dockWidget_Fog_pref_destroyed()
{
    ui->actionFog->setChecked(false);
}
void MainWindow::on_dockWidget_Fog_pref_visibilityChanged(bool visible)
{
    ui->actionFog->setChecked(visible);
}
void MainWindow::on_checkBoxSkyVisible_toggled(bool checked)
{
     ui->glWidget->showSky=checked;
}
void MainWindow::on_checkBoxGroundVisible_toggled(bool checked)
{
     ui->glWidget->showMap=checked;
}
void MainWindow::on_checkBoxFogVisible_toggled(bool checked)
{
     ui->glWidget->enFog(checked);
}
void MainWindow::on_fogDens_valueChanged(int value)
{
       ui->glWidget->setFogDensity(value/1000.0);
      ui->densLbl->setText((QString)"Density (" + QString::number(ui->glWidget->density) + ")");
      this->repaint();
}
